From 3f0ef765c08b24184a1445b119513dfc7575dd8e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Apr 2015 10:23:08 -0700 Subject: [PATCH] Add support for platform-specific build/dev dependencies They're available at the top-level, so no reason to not expose them at the target level as well! Closes #1464 --- src/cargo/util/toml.rs | 14 +++++++ tests/test_cargo_compile.rs | 76 +++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index e653ab0fc..3a50195ee 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -465,6 +465,18 @@ impl TomlManifest { |dep| { dep.set_only_for_platform(Some(name.clone())) })); + try!(process_dependencies(&mut cx, + platform.build_dependencies.as_ref(), + |dep| { + dep.set_only_for_platform(Some(name.clone())) + .set_kind(Kind::Build) + })); + try!(process_dependencies(&mut cx, + platform.dev_dependencies.as_ref(), + |dep| { + dep.set_only_for_platform(Some(name.clone())) + .set_kind(Kind::Development) + })); } } } @@ -589,6 +601,8 @@ enum PathValue { #[derive(RustcDecodable)] struct TomlPlatform { dependencies: Option>, + build_dependencies: Option>, + dev_dependencies: Option>, } impl TomlTarget { diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 3faea78b5..a80a85688 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -9,6 +9,7 @@ use support::{COMPILING, RUNNING, ProjectBuilder}; use hamcrest::{assert_that, existing_file, is_not}; use support::paths::CargoPathExt; use cargo::util::process; +use cargo::ops::rustc_version; fn setup() { } @@ -1386,48 +1387,67 @@ Caused by: ")); }); -#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_os = "linux"))] test!(cargo_platform_specific_dependency { + let (_, host) = rustc_version().unwrap(); let p = project("foo") - .file("Cargo.toml", r#" + .file("Cargo.toml", &format!(r#" [project] - name = "foo" version = "0.5.0" authors = ["wycats@example.com"] + build = "build.rs" - [target.i686-unknown-linux-gnu.dependencies.bar] - path = "bar" - [target.x86_64-unknown-linux-gnu.dependencies.bar] - path = "bar" + [target.{host}.dependencies] + dep = {{ path = "dep" }} + [target.{host}.build-dependencies] + build = {{ path = "build" }} + [target.{host}.dev-dependencies] + dev = {{ path = "dev" }} + "#, host = host)) + .file("src/main.rs", r#" + extern crate dep; + fn main() { dep::dep() } "#) - .file("src/main.rs", - &main_file(r#""{}", bar::gimme()"#, &["bar"])) - .file("bar/Cargo.toml", r#" + .file("tests/foo.rs", r#" + extern crate dev; + #[test] + fn foo() { dev::dev() } + "#) + .file("build.rs", r#" + extern crate build; + fn main() { build::build(); } + "#) + .file("dep/Cargo.toml", r#" [project] - - name = "bar" + name = "dep" version = "0.5.0" authors = ["wycats@example.com"] "#) - .file("bar/src/lib.rs", r#" - pub fn gimme() -> String { - "test passed".to_string() - } - "#); + .file("dep/src/lib.rs", "pub fn dep() {}") + .file("build/Cargo.toml", r#" + [project] + name = "build" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("build/src/lib.rs", "pub fn build() {}") + .file("dev/Cargo.toml", r#" + [project] + name = "dev" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("dev/src/lib.rs", "pub fn dev() {}"); - p.cargo_process("build") - .exec_with_output() - .unwrap(); + assert_that(p.cargo_process("build"), + execs().with_status(0)); assert_that(&p.bin("foo"), existing_file()); - - assert_that(process(&p.bin("foo")).unwrap(), - execs().with_stdout("test passed\n")); + assert_that(p.cargo_process("test"), + execs().with_status(0)); }); -#[cfg(not(all(any(target_arch = "x86", target_arch = "x86_64"), target_os = "linux")))] -test!(cargo_platform_specific_dependency { +test!(bad_platform_specific_dependency { let p = project("foo") .file("Cargo.toml", r#" [project] @@ -1436,9 +1456,7 @@ test!(cargo_platform_specific_dependency { version = "0.5.0" authors = ["wycats@example.com"] - [target.i686-unknown-linux-gnu.dependencies.bar] - path = "bar" - [target.x86_64-unknown-linux-gnu.dependencies.bar] + [target.wrong-target.dependencies.bar] path = "bar" "#) .file("src/main.rs", @@ -1459,7 +1477,7 @@ test!(cargo_platform_specific_dependency { "#); assert_that(p.cargo_process("build"), - execs().with_status(101)); + execs().with_status(101)); }); test!(cargo_platform_specific_dependency_wrong_platform { -- 2.30.2